<template>
	<view class="main-class">
		<tn-sticky>
			<view class="header-class tn-flex justify-end" >
				<view class="status_bar" style="height: var(--status-bar-height); width: 100%; "></view>			
				<tn-navbar height="45px" home-icon="" :bottom-shadow = "false" bg-color="tn-type-primary_bg" text-color="tn-white">订单详情 </tn-navbar>
			</view>
			<view class="tn-p tn-white_bg">
				<view class="tn-pt-xs">
					客户名称：{{orderInfoData.businessname}}
				</view>	
				<view class="tn-pt-xs">
					单据编号：{{orderInfoData.billcode}}
				</view>	
				<view class="tn-pt-xs">
					下单人：{{orderInfoData.caozyname}}
				</view>	
				<!-- <view class="tn-pt-xs">
					收货人：{{orderInfoData.recemanname}} {{orderInfoData.recetelephone}}
				</view>	
				<view class="tn-pt-xs">
					收货地址：{{orderInfoData.address}}
				</view>	 -->
				<view class="tn-pt-xs">
					备注：{{orderInfoData.remark}}
				</view>	
			</view>
		</tn-sticky>
		<hr/>
		<view class="tn-pl tn-pr tn-radius tn-pb scroll-view-class">
			<view class="tn-shadow-md tn-pl-sm tn-pt-sm tn-pb-sm"  v-for="(item, index) in orderInfoData.details">
				<view class="tn-text-xl tn-text-ellipsis-2 tn-pr-xs tn-pt-xs">
					{{item.rfbillcode}}
				</view>
				<view class="tn-pt-xs tn-flex-row">
					{{item.orderinfo}}
				</view>	
				<view class="tn-pt-xs">
					{{item.invoice1info}}
				</view>
				<view class="tn-pt-xs">
					{{item.invoice2info}}
				</view>
				<view class="tn-pt-xs">
					{{item.invoice3info}}
				</view>
				<view class="tn-pt-xs">
					{{item.invoice4info}}
				</view>
			</view>
		</view>
		<view class="bottom-buttons" >
		<!--  <view class="tn-p-xl tn-type-success_bg">
		  	金额：{{orderInfoData.taxamount}}
		  </view> -->
		  <view class="">
		  	<tn-button type="success" size="xl" class="tn-ml-sm tn-mr-sm  "  style="flex-grow: 1;" >金额：{{orderInfoData.taxamount}}</tn-button>
		  </view>
		  <view class="">
			<tn-button type="danger" size="xl"class="tn-ml-sm tn-mr-sm "  style="flex-grow: 1;"  @click="toUnEnd">驳回</tn-button>
		  </view>
		  <view class="">
		  	<tn-button type="success" size="xl" class="tn-ml-sm tn-mr-sm "  style="flex-grow: 1;"  @click="toEnd">通过</tn-button>
		  </view>
		  
		</view>
	</view>
	
	
</template>

<script setup>
	import { ref,reactive,onMounted } from 'vue'
	import { postCall,postReturnPay } from '@/api/index.js'
	import { EventBus } from '@/mitt/EventBus.js';
	import { toastMessage } from '@/utils/toast.js'
	import { createParams } from '@/utils/utils.js'
	import { v4 as uuidv4 } from 'uuid';
	
	let userInfo = reactive({});
	const procName = "PROC_APP_DO_INVOICE";
	const payConfig = {};
	let orderInfoData = reactive({});
	
	onMounted(()=>{
		const tempOrderInfo = uni.getStorageSync("ORDERINFO");
		Object.assign(orderInfoData,tempOrderInfo);
		doGetPayConfig();
		userInfo = uni.getStorageSync('USERINFO');
	})
	 
	let doGetPayConfig = async () =>{
		let params = {};
		params["P_PROC_NAME"] = "PROC_APP_DO_SHOPPING";
		params["P_ACTION"] = "PAYCONFIG";		
		await postCall(params).then(res=>{
			if(res){
				if(res.code===200){
					Object.assign(payConfig,res.data.DATASET[0]);
				}
			}
			
		})
	}
	 

	let toUnEnd = async ()=>{
	
		let params = {};
		params["P_PROC_NAME"] = procName;
		params["P_ACTION"] = "NO";
		params["P_BILLNO"] = orderInfoData.billno;
		await postCall(params).then(res=>{
			if(res){
				if(res.code===200){
					toastMessage("驳回成功！");
					uni.navigateTo({
					  url: '/pages/invoice/invoice'
					})
				}
			}
		})  
	}
	
	let toEnd =()=>{
		let params = {};
		params["P_PROC_NAME"] = procName;
		params["P_ACTION"] = "YES";
		params["P_BILLNO"] = orderInfoData.billno;
		postCall(params).then(res=>{
			if(res){
				if(res.code===200){
					   toastMessage("审批完成！");
					   uni.navigateTo({
						url: '/pages/invoice/invoice'
					   })
				}
			}
		   
		}) 
	}
	
	let onLineReturn = async (oldtrxid,trxamt) =>{
		let guid = uuidv4();
		let params = {};
		params.cusid = payConfig.cusid;
		params.appid = payConfig.appid;
		params.version = "11";
		params.reqsn = guid;
		params.trxamt = (trxamt*100).toString();
		params.oldtrxid = oldtrxid;
		params.randomstr = guid;
		params.signtype = payConfig.signtype;
		await postReturnPay(params).then(res=>{
			if(res){
				if(res.code===200){
					if(res.data.errmsg){
						toastMessage(res.data.errmsg)
					}
					if(res.data.trxstatus){
						if(res.data.trxstatus=="0000"){
							toastMessage("作废成功！");
						}
					}
				}
			}
		})
	}
	
	const modifyShopping=(val,index)=>{
		let params = {};
		params["P_PROC_NAME"] = "PROC_APP_DO_ORDER";
		params["P_ACTION"] = "LOCALMODIFY";
		params["P_INNERPRICE"] = val.innerprice;
		params["P_BILLCODESN"] = val.billcodesn;
		params["P_BILLCODE"] = orderInfoData.billcode;
		postCall(params).then(res=>{
			if(res){
				if(res.code===200){
					toastMessage("修改成功！");
				}
			}
		})
		
	}
	
</script>

<style scoped>
.header-class{
	height: 17vh !important;
	flex-direction: column
}
.form-class{
	width: 90vw;
	margin-left: 5vw;
}
.button-class{
	margin-top: 5vh;
	width: 90vw;
	border-radius: 40px !important;
	/* color: #FFFFFF !important; */
	background: linear-gradient(to right,  #47e8be,#3379dc);
	/* border: 0px solid rgba(0, 0, 0, 0.2) !important; */
}

.bottom-buttons {
	position: fixed;
	bottom: 0;
	left: 0;
	width: 100%;
	background-color: #fff; 
	padding: 10px; 
	
	box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.1); 
	padding-bottom: calc(env(safe-area-inset-bottom) + 20px);
	height: 9vh;
	display: flex;
	justify-content: space-between;
}

.scroll-view-class{
	padding-bottom: 8.5vh;
}

.button-class::after{
	border: 0px solid rgba(0, 0, 0, 0.2) !important;
}

.popup-calendar-button {
  margin: 0rpx 30rpx;
  width: calc(100% - 60rpx) !important;
  padding: 20rpx 30rpx !important;
}

.no-data-class{
	
	display: flex;
	justify-content: center;
	align-items: center;
	padding-top: 10vh;
}
</style>
